"""
暴力搜索模型参数
"""


def grid_search(func, train_x, train_y, test_x, test_y,
                unit_arr, act_arr, opt_arr, loss_arr,
                epochs,  batch_size, workers, use_multiprocessing,
                shuffle, plot, **options):
    """

    :param func:
    :param train_x:
    :param train_y:
    :param test_x:
    :param test_y:
    :param unit_arr:
    :param act_arr:
    :param opt_arr:
    :param loss_arr:
    :param epochs:
    :param batch_size:
    :param workers:
    :param use_multiprocessing:
    :param shuffle:
    :param plot:
    :return:
    """
    loss_metrics = 10000

    target_unit = None
    target_act = None
    target_opt = None
    target_loss = None

    for unit in unit_arr:
        for act in act_arr:
            for opt in opt_arr:
                for loss in loss_arr:
                    print('*' * 100)
                    _, mid_loss = func(train_x=train_x, train_y=train_y,
                                       test_x=test_x, test_y=test_y,
                                       unit=unit,
                                       act=act,
                                       opt=opt,
                                       loss=loss,
                                       epochs=epochs,
                                       batch_size=batch_size,
                                       verbose=0,
                                       model_name=None,
                                       pic_path=None,
                                       workers=workers,
                                       use_multiprocessing=
                                       use_multiprocessing,
                                       shuffle=shuffle,
                                       plot=plot,
                                       **options)
                    #
                    # if kernel_size and not drop_p:
                    #     _, mid_loss = func(train_x=train_x, train_y=train_y,
                    #                        test_x=test_x, test_y=test_y,
                    #                        unit=unit,
                    #                        act=act,
                    #                        opt=opt,
                    #                        loss=loss,
                    #                        epochs=epochs,
                    #                        batch_size=batch_size,
                    #                        verbose=0,
                    #                        model_name=None,
                    #                        pic_path=None,
                    #                        workers=workers,
                    #                        use_multiprocessing=
                    #                        use_multiprocessing,
                    #                        shuffle=shuffle,
                    #                        plot=plot,
                    #                        kernel_size=kernel_size)
                    #
                    # elif kernel_size and drop_p and drop_p >= 0:
                    #     _, mid_loss = func(train_x=train_x, train_y=train_y,
                    #                        test_x=test_x, test_y=test_y,
                    #                        unit=unit,
                    #                        act=act,
                    #                        opt=opt,
                    #                        loss=loss,
                    #                        epochs=epochs,
                    #                        batch_size=batch_size,
                    #                        verbose=0,
                    #                        model_name=None,
                    #                        pic_path=None,
                    #                        workers=workers,
                    #                        use_multiprocessing=
                    #                        use_multiprocessing,
                    #                        shuffle=shuffle,
                    #                        plot=plot,
                    #                        kernel_size=kernel_size,
                    #                        drop_p=drop_p)
                    #
                    # else:
                    #     _, mid_loss = func(train_x=train_x, train_y=train_y,
                    #                        test_x=test_x, test_y=test_y,
                    #                        unit=unit,
                    #                        act=act,
                    #                        opt=opt,
                    #                        loss=loss,
                    #                        epochs=epochs,
                    #                        batch_size=batch_size,
                    #                        verbose=0,
                    #                        model_name=None,
                    #                        pic_path=None,
                    #                        workers=workers,
                    #                        use_multiprocessing=
                    #                        use_multiprocessing,
                    #                        shuffle=shuffle,
                    #                        plot=plot)

                    mid_loss = mid_loss[0] if isinstance(mid_loss, list) \
                        else mid_loss

                    if mid_loss < loss_metrics:
                        loss_metrics = mid_loss
                        target_act = act
                        target_opt = opt
                        target_unit = unit
                        target_loss = loss

    loss_info = 'loss: {}, act: {}, opt; {}， unit; {}, loss: {}'. \
        format(loss_metrics, target_act, target_opt, target_unit, target_loss)
    print(loss_info)
